package com.zengde.ai_sandbox.controller;

import com.zengde.ai_sandbox.service.OssFileService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/api")
public class UploadController {

    @Autowired
    private OssFileService ossFileService;

    @PostMapping("/uploadTemp")
    public Map<String, Object> uploadTemp(
            @RequestParam("file") MultipartFile file,
            @RequestParam("type") int type
    ) throws IOException {
        String url = ossFileService.uploadTempFile(file, type);

        Map<String, Object> result = new HashMap<>();
        result.put("code", 1);
        result.put("msg", "success");
        result.put("data", Map.of("url", url));
        return result;
    }
}